<?php

/**
 * @author Dileesh Meladath
 * @copyright 2011
 */
 
    include_once("../includes/appdata.php");
    require_once(APP_DIRECTORY."/php/include.php");
    
    spl_autoload_register('__autoload');
    
    $lblMgr = new LabelManager();
    
    if( isset($_POST["from"])) {
        $labelName = $lblMgr->getLabelEngValue($_POST["labelid"]);
        $labeldata = $lblMgr->getLabelDetails($_POST["labelid"]);
        //printObject($labeldata); exit;
    } else if( isset($_POST["btnUpdateLabel"]) ) {
        
        $langList = $langMgr->getLanguageList();
        $langArray = array();
        
        foreach( $langList as $lang )   {
            if($_POST["txtLabelValue_".$lang["id"]] != "")
            {
                $langs = array("id" => $lang["id"], "value" => $_POST["txtLabelValue_".$lang["id"]]);
                array_push($langArray,$langs);  
            }  
        }
        
        if(count($langArray) > 0) {                
            $lblMgr->updateLabel($_POST["labelId"], $langArray);   
            header('Location: listlabels.php');
        }                                                
    } else {
        header('Location: listlabels.php');
    }    
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>PowerMan - Page Title</title>
        <link rel="shortcut icon" href="<?php echo ROOT_DIR; ?>favicon.ico" type="image/x-icon" />
        
        <link rel="stylesheet" href="<?php echo ROOT_DIR; ?>css/common.css" type="text/css" media="screen" title="default" />
        <link rel="stylesheet" href="<?php echo ROOT_DIR; ?>css/main.css" type="text/css" media="screen" title="default" />
        <link rel="stylesheet" href="<?php echo ROOT_DIR; ?>css/form.css" type="text/css" media="screen" title="default" />
        <link rel="stylesheet" href="<?php echo ROOT_DIR; ?>css/tabing.css" type="text/css" media="screen" title="default" />
        <link rel="stylesheet" href="<?php echo ROOT_DIR; ?>css/jquery.autocomplete.css" type="text/css" media="screen" title="default" />
        
        <!--[if IE]>
        <link rel="stylesheet" media="all" type="text/css" href="css/ie.css" />
        <![endif]-->
        
        <!--  jquery core & library -->
        <script src="<?php echo ROOT_DIR; ?>js/jquery-1.5.2.min.js" type="text/javascript"></script>
        <script src="<?php echo ROOT_DIR; ?>js/jquery.validate.js" type="text/javascript"></script>
        <script src="<?php echo ROOT_DIR; ?>js/jquery.autocomplete.js" type="text/javascript" ></script>
        <script src="<?php echo ROOT_DIR; ?>js/additional-methods.js" type="text/javascript"></script>
        <script src="<?php echo ROOT_DIR; ?>js/jquery.validate.messages.js" type="text/javascript"></script>
        <link type="text/css" href="<?php echo ROOT_DIR; ?>css/ui-darkness/jquery-ui-1.8.7.custom.css" rel="stylesheet" />	
		<script type="text/javascript" src="<?php echo ROOT_DIR; ?>js/jquery-ui-1.8.7.custom.js"></script>
        
        <!--  styled file upload script --> 
        <script src="<?php echo ROOT_DIR; ?>js/jquery.filestyle.js" type="text/javascript"></script>
        
        <script src="<?php echo ROOT_DIR; ?>js/lib.js" type="text/javascript"></script>
        <script src="<?php echo ROOT_DIR; ?>js/powerman.js" type="text/javascript"></script>
    </head>
    <body>   
        
        <!-- start content-outer -->
        <div id="content-outer">
            <!-- start content -->
            <div id="content">
                <div id="page-heading"><h1>Update Label</h1></div>
        
                <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
                    <tr>
                        <th rowspan="3" class="sized">
                            <img src="<?php echo ROOT_DIR; ?>images/side_shadowleft.jpg" width="20" height="300" alt="" />
                        </th>
                        <th class="topleft"></th>
                        <td id="tbl-border-top">&nbsp;</td>
                        <th class="topright"></th>
                        <th rowspan="3" class="sized">
        
                            <img src="<?php echo ROOT_DIR; ?>images/side_shadowright.jpg" width="20" height="300" alt="" />
                        </th>
                    </tr>
                    <tr>
                        <td id="tbl-border-left"></td>
                        <td>
        
        <!--  start content-table-inner -->
        <div id="content-table-inner">
            <!--  start table-content  -->
        
        	<div id="table-content">
                </div>
            
            <table border="0" width="100%" cellpadding="0" cellspacing="0">
                <tr valign="top">
                    <td>
                        <!-- start id-form -->
                        <form id="frmUpdateLabel" method="POST">
                            <input type="hidden" name="labelId" value="<?php echo $_POST["labelid"]; ?>"/>
                            <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                <tr>
        
                                    <th valign="top"><label for="txtLabelName">Label Name:</label><em>*</em></th>
                                    <td><input type="text" name="txtLabelName" value="<?php echo $labelName; ?>" class="inp-form-med" readonly="true" /></td>
                                </tr>
                                <?php   
                                foreach( $labeldata as $labeld )
                                {?>                                
                                <tr>
                                    <th valign="top"><?php echo $labeld["langName"]; ?> Label:</th>
                                    <td>
                                        <textarea class="form-textarea" name="txtLabelValue_<?php echo $labeld["id"]; ?>"><?php echo $labeld["value"]; ?></textarea>                         
                                    </td>                                    
                                </tr>                                
                                <?php
                                }                                
                                ?>
                                                           
                                <tr>
                                	<th>&nbsp;</th>
                                	<td valign="top">
                                        <input type="submit" name="btnUpdateLabel" value="" class="form-update" />                                		
                                	</td>
                                	<td></td>
                                </tr>
                            </table>
                        </form>
                        <!-- end id-form  -->                                  
                    </td>
        
                    <td>
                        <!--  start related-activities -->
        <div id="related-activities">
            
            <!--  start related-act-top -->
            <div id="related-act-top">
            <img src="<?php echo ROOT_DIR; ?>images/forms/header_related_act.gif" width="271" height="43" alt="" />
            </div>
            <!-- end related-act-top -->
            
            <!--  start related-act-bottom -->
        
            <div id="related-act-bottom">
            
            	<!--  start related-act-inner -->
            	<div id="related-act-inner">
            	
            		<div class="left"><a href=""><img src="<?php echo ROOT_DIR; ?>images/forms/icon_plus.gif" width="21" height="21" alt="" /></a></div>
            		<div class="right">
            			<h5>Add another label</h5>
            			Manage your labels through this application.
            			Add all your labels.
            			<ul class="greyarrow">
            				<li><a href="addlabel.php">Click here add</a></li> 
            			</ul>
        
            		</div>
            		
            		<div class="clear"></div>            		
            	</div>
            	<!-- end related-act-inner -->
            	<div class="clear"></div>
            
            </div>
                <!-- end related-act-bottom -->
            
        </div>
        <!-- end related-activities -->                </td>
        
                </tr>
                <tr>
                    <td><img src="<?php echo ROOT_DIR; ?>images/blank.gif" width="695" height="1" alt="blank" /></td>
                    <td></td>
                </tr>
            </table>
        </div>
        <!--  end content-table-inner  -->
        
                        </td>
        
                        <td id="tbl-border-right"></td>
                    </tr>
                    <tr>
                        <th class="sized bottomleft"></th>
                        <td id="tbl-border-bottom">&nbsp;</td>
                        <th class="sized bottomright"></th>
                    </tr>
                </table>
            </div>
        
        </div>
<!--  end content-outer -->
        
        
        <div class="clear">&nbsp;</div>


        <!-- start footer -->         
        <div id="footer">
        	<!--  start footer-left -->
        	<div id="footer-left">
        	PowerMan &copy; Copyright. All rights reserved.</div>

        	<!--  end footer-left -->
        	<div class="clear">&nbsp;</div>
        </div>
        <!-- end footer -->
        
    </body>
  </html>